/**
 * 北京钉图互动科技 all right reserver
 */
package com.impress.commons.vo;

import java.util.List;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * @author Wangyi
 * @since 2016年6月13日
 */
@ApiModel(value = "数据分片,无总记录总")
public class Slice<T> extends Chunk<T> {

	private static final long serialVersionUID = 6368839449441169559L;

	public static final Slice<?> EMPTY_SLICE = new Slice<>();

	@ApiModelProperty(value = "页号,1开始", required = true)
	private int number;

	@ApiModelProperty(value = "页尺寸,大于0", required = true)
	private int size;

	@ApiModelProperty(value = "是否有下页", required = true)
	private boolean hasNext;

	/**
	 * 
	 */
	public Slice() {
	}

	/**
	 * @param number
	 * @param size
	 * @param hasNext
	 */
	public Slice(int number, int size, List<T> content, boolean hasNext) {
		super();
		this.number = number;
		this.size = size;
		this.hasNext = hasNext;
		this.setContent(content);
	}
	
	/**
	 * 通过content来设置是否有next
	 * @param number
	 * @param size
	 * @param content
	 */
	public Slice(int number, int size, List<T> content) {
		super();
		this.number = number;
		this.size = size;
		this.setContent(content);
		if(null!=content&&content.size()>0)
		{
			this.hasNext= size==content.size()? true:false;
		}
	}
	
	 

	public static final <T> Slice<T> emptySlice() {
		return (Slice<T>) EMPTY_SLICE;
	}

	/**
	 * Returns the number of the current {@link Slice}. Is always non-negative.
	 * 
	 * @return the number of the current {@link Slice}.
	 */
	public int getNumber() {
		return number;
	}

	/**
	 * @param number the number to set
	 */
	public void setNumber(int number) {
		this.number = number;
	}

	/**
	 * @return the size
	 */
	public int getSize() {
		return size;
	}

	/**
	 * @param size the size to set
	 */
	public void setSize(int size) {
		this.size = size;
	}

	/**
	 * @return the hasNext
	 */
	public boolean isHasNext() {
		return hasNext;
	}

	/**
	 * @param hasNext the hasNext to set
	 */
	public void setHasNext(boolean hasNext) {
		this.hasNext = hasNext;
	}

}
